package com.autonavi.yunda.yunji.service.model;

import com.autonavi.yunda.yunji.core.enums.BpmsApprovalStatus;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

@Data
@Builder
public class BpmsTaskVO {
    private Long taskId;
    private String processInstanceId;
    private String title;
    private String url;
    private String outResult;
    private String taskStatus;
    private String actualActionerId;
    // 申请人
    private String originatorUserId;

    public static BpmsTaskVO fromJsonMap(Map<String, Object> map) {
        return BpmsTaskVO.builder()
                .taskId(Long.valueOf(map.get("id") + ""))
                .processInstanceId((String) map.get("processInstanceId"))
                .title((String) map.get("title"))
                .url((String) map.get("url"))
                .outResult((String) map.get("outResult"))
                .actualActionerId((String) map.get("actualActionerId"))
                .originatorUserId((String) map.get("originatorUserId"))
                .taskStatus((String) map.get("taskStatus"))
                .build();
    }

    public BpmsApprovalStatus getBpmsApprovalStatus() {
        if (StringUtils.isEmpty(outResult)) {
            if (taskStatus.equals(BpmsApprovalStatus.TERMINATED.name())) {
                return BpmsApprovalStatus.TERMINATED;
            } else {
                return BpmsApprovalStatus.INIT;
            }
        } else if ("Agree".equals(outResult)) {
            return BpmsApprovalStatus.AGREE;
        } else {
            return BpmsApprovalStatus.DISAGREE;
        }
    }
}
